package com.palnar.ilecker.model;

import java.io.Serializable;
import java.util.HashMap;

import org.ksoap2.serialization.SoapObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.palnar.ilecker.utils.XmlDocumentUtility;

public class SpecificationMember extends ItemBase implements Serializable 
{

	private Integer clientId = 0;
	private Integer serverId = 0;
	private String name = "";
	private String code = "";
	private Integer specificationGroupId = 0;
	private Integer specificationGroupName = 0;
	private Boolean isDefault;

	private static String idArg = "Id";
	private static String nameArg = "Name";
	private static String specificationGroupIdArg = "SpecificationGroupId";
	private static String specificationGroupNameArg = "SpecificationGroupName";

	public SpecificationMember() {
	}
	
	
	public int getClientId()
	{
		return this.clientId;
	}
	
	public int getServerId()
	{
		return this.serverId;
	}

//	public String getName() 
//	{
//		return this.name;
//	}

	public String getCode() 
	{
		return this.code;
	}
	public int getSpecificationGroupID() 
	{
		return this.specificationGroupId;
	}

//	 public String getSpecificationGroupName()
//	 {
//		 return this.specificationGroupName;
//	 }
	 public Integer getSpecificationGroupName()
	 {
		 return this.specificationGroupName;
	 }
	 public Boolean getIsDefault()
	 {
		 return isDefault;	 
	 }
	 
//	 public void SetSpecificationGroupName(String value)
//	 {
//		 this.specificationGroupName = value;
//	 }
	 public void SetSpecificationGroupName(Integer value)
	 {
		 this.specificationGroupName = value;
	 }

	public void setClientId(int id) {
		this.clientId = id;
	}
	
	public void setServerId(int id) {
		this.serverId = id;
	}

//	public void setName(String name) {
//		this.name = name;
//	}

	public void setCode(String code) {
		this.code = code;
	}
	
	public void setSpecificationGroupID(int specificationGroupId) {
		this.specificationGroupId = specificationGroupId;
	}
	
	public void setIsDefault(Boolean isDefault)
	 {
		 this.isDefault = isDefault;	 
	 }

//	 public void setSpecificationGroupName(String specificationGroupName) {
//	 this.specificationGroupName = specificationGroupName;
//	 }

	//
	// public static List<SpecificationMember> MenuItemGroupBuilder1(SoapObject
	// outputSoapObject)
	// {
	// SoapObject specificationMemberSoapObject = (SoapObject)
	// outputSoapObject.getProperty(2);
	//
	// List<SpecificationMember> specificationMemberList = new
	// ArrayList<SpecificationMember>();
	//
	// if(specificationMemberSoapObject.getPropertyCount() >0)
	// {
	// SpecificationMember specificationMember = new SpecificationMember();
	// specificationMember.id =
	// Integer.parseInt(specificationMemberSoapObject.getProperty("ItemId").toString());
	// specificationMember.name =
	// specificationMemberSoapObject.getProperty("ItemName").toString();
	// specificationMember.specificationGroupId =
	// Integer.parseInt(specificationMemberSoapObject.getProperty(2).toString());
	// specificationMemberList.add(specificationMember);
	// }
	// return specificationMemberList;
	// // TODO Auto-generated method stub
	// }

	public static SpecificationMember SpecificationMemberBuilder(
			SoapObject specMemberSoapObject, HashMap<Integer, Language> languages)
	{

		SpecificationMember specificationMember = new SpecificationMember();
		if (specMemberSoapObject.getPropertyCount() > 0)
		{
			specificationMember.serverId = Integer.parseInt(specMemberSoapObject.getProperty("Id").toString());
			Object codeObj = specMemberSoapObject.getProperty("Code");
			if(codeObj != null)
			{
				if (!codeObj.toString().equals(XmlDocumentUtility.nullString))
				{
					specificationMember.code =  codeObj.toString();
				}
			}
			if (specMemberSoapObject.getProperty("Name") != null)
			{
				specificationMember.setName(Integer.parseInt(specMemberSoapObject.getProperty("Name").toString()));
			}
			specificationMember.isDefault = Boolean.parseBoolean(specMemberSoapObject.getProperty("IsDefault").toString());
		}
		

//		SoapObject specificationDetailsNameSoapObject = (SoapObject)specMemberSoapObject.getProperty("DisplayNames");
//		specificationMember.TextNameBuilder(specificationDetailsNameSoapObject, languages);
		return specificationMember;
		// TODO Auto-generated method stub

	}

	public void getSerializationData(Element parentElement, Document document) {

		Element idElement = document.createElement(idArg);
		Node idNode = document.createTextNode("id");
		idNode.setNodeValue(serverId.toString());
		idElement.appendChild(idNode);
		parentElement.appendChild(idElement);

		Element nameElement = document.createElement(nameArg);
		Node nameNode = document.createTextNode("name");
		nameNode.setNodeValue(getServerNameId().toString());
		nameElement.appendChild(nameNode);
		parentElement.appendChild(nameElement);

		Element SpecificationGroupIdElement = document
				.createElement(specificationGroupIdArg);
		Node SpecificationGroupIdNode = document
				.createTextNode("specificationGroupId");
		SpecificationGroupIdNode.setNodeValue(specificationGroupId.toString());
		SpecificationGroupIdElement.appendChild(SpecificationGroupIdNode);
		parentElement.appendChild(SpecificationGroupIdElement);

		Element SpecificationGroupNameElement = document
				.createElement(specificationGroupNameArg);
		Node SpecificationGroupNameNode = document
				.createTextNode("specificationGroupName");
		SpecificationGroupNameNode.setNodeValue(specificationGroupName.toString());
		SpecificationGroupNameElement.appendChild(SpecificationGroupNameNode);
		parentElement.appendChild(SpecificationGroupNameElement);

	}

	public static SpecificationMember SpecificationMemberTypeBuilder(
			SoapObject object) {

		SpecificationMember specMemeber = new SpecificationMember();

		Object idObj = object.getProperty("Id");
		if (!idObj.toString().equals(XmlDocumentUtility.nullString)) {
			specMemeber.setServerId(Integer.parseInt(idObj.toString()));
		}

		Object nameObj = object.getProperty("Name");

		if(nameObj != null)
		{
			if (!nameObj.toString().equals(XmlDocumentUtility.nullString))
			{
				specMemeber.setServerNameId(Integer.parseInt(nameObj.toString()));
			}
		}

		Object specificationGroupIdObj = object
				.getProperty("SpecificationGroupId");

		if (!specificationGroupIdObj.toString().equals(XmlDocumentUtility.nullString)) {
			specMemeber.setSpecificationGroupID(Integer
					.parseInt(specificationGroupIdObj.toString()));

		}

		Object specificationGroupNameObj = object
				.getProperty("SpecificationGroupName");
		if(specificationGroupNameObj != null)
		{

			if (!specificationGroupNameObj.toString().equals(XmlDocumentUtility.nullString))
			{
				specMemeber.SetSpecificationGroupName(Integer.parseInt(specificationGroupNameObj.toString()));
			}
		}

		return specMemeber;
	}
}
